<?php
class GlobalSettings
{
  
   const DISABLE_INITIALIZER = false;
   const RELEASE_MODE = false;
   const MAX_UPLOAD_TIME = 1800;
   const COURSEWARE_ROOT_PATH = "CoursewareRoot";
   const USER_SESSION = "UserSession";
   const UPLOAD_SESSON = "UploadSession";
   const SEARCH_PAGE_SIZE = 50;
   const MAX_INPUT_STR_LEN = 100;
   const MAX_KEYWORDS_COUNT = 4;
   
   protected static $instance = NULL;
   
   protected $overrideSettings = NULL;
   protected $defaultSettings = array();
   
   public static function instance()
   {
       if(NULL == self::$instance)
	   {
	         self::$instance = new self();
	   }
	   
	   return self::$instance;
   }
   
   public function getSetting($key)
   {
      if(isset($this->overrideSettings[$key]))
	  {
	      return $this->overrideSettings[$key];
	  }
	  
	  if(isset($this->defaultSettings[$key]))
	  {
	      return $this->defaultSettings[$key];
	  }
	  
	  if($key == self::COURSEWARE_ROOT_PATH)
	  {
	      $dir = dirname(__FILE__)."/../../public/courseware";
		  $this->defaultSettings[self::COURSEWARE_ROOT_PATH] = $dir;
		  return $dir;
	  }
	  
	  return "";
   }
   
   protected function __construct()
   {
	  $configFile = dirname(__FILE__).'/../configs/globalSettings.ini';
	  $this->overrideSettings = parse_ini_file($configFile);
	  
	  if(FALSE === $this->overrideSettings)
	  {
		 throw new ErrorException("Parsing ".$configFile." failed!");
	  }
   }
}